/* 
输入：strs = ["flower","flow","flight"]
输出："fl"
*/
const strs = ["flower", "flow", "flight"];
function longestCommonPrefix(strs) {
  for (let i = 0; i < strs[0].length; i++) {
    const char = strs[0][i];
    for (let j = 1; j < strs.length; j++) {
      if (strs[j][i] !== char || i === strs[j].length) {
        return strs[0].slice(0, i);
      }
    }
  }
  return strs[0];
}

console.log(longestCommonPrefix(strs));

